<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>角色列表</title>
    <#include "/layout/css.html"/>
</head>
<body class="body">

<!-- 工具集 -->
<div class="my-btn-box">
    <form class="layui-form" action="" id="searchWhereForm"  onsubmit="return false">
	    <span class="fl">
	        <span class="layui-form-label">搜索条件：</span>
	        <div class="layui-input-inline">
				<input type="text" name="name" placeholder="请输入角色名" class="layui-input">
			</div>
			<div class="layui-input-inline">
				<input type="text" name="roleCode"  placeholder="请输入角色code" class="layui-input">
			</div>
	        <button class="layui-btn mgl-20" id="btn-search">查询</button>
	    </span>
	     
    </form>
</div>
<span class="fl">
	<button class="layui-btn mgl-20" id="btn-add">添加</button>
	<button class="layui-btn mgl-20" id="btn-edit">编辑</button>
	<button class="layui-btn mgl-20" id="btn-give">分配菜单</button>
	<button class="layui-btn mgl-20" id="btn-del">删除</button>
</span>
<hr>
<!-- 表格 -->
<div id="dateTable"></div>

<#include "/layout/js.html"/>
<script type="text/javascript">
    // layui方法
    layui.use(['table', 'form', 'layer', 'vip_table'], function () {
        // 操作对象
        var form = layui.form
                , table = layui.table
                , layer = layui.layer
                , vipTable = layui.vip_table
                , $ = layui.jquery;
        var table = layui.table;
        //第一个实例
        var tableObj = table.render({
          elem: '#dateTable'
          ,height: vipTable.getFullHeight()
          ,url: '${basePath}/role/listData' //数据接口
          ,page: true //开启分页
          ,limits: [10, 30, 60, 90, 150]
       	  ,limit: 10 //默认采用30
       	  ,loading: true
       	  ,where:$("#searchWhereForm").serializeObject()
	      ,request: {
	       	  pageName: 'pageNum' //页码的参数名称，默认：page
	       	  ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	      }
          ,response: {
        	  statusName: 'code' //数据状态的字段名称，默认：code
        	  ,statusCode: "0000" //成功的状态码，默认：0
        	  ,msgName: 'message' //状态信息的字段名称，默认：msg
        	  ,countName: 'total' //数据总数的字段名称，默认：count
        	  ,dataName: 'records' //数据列表的字段名称，默认：data
        	}     
          ,cols: [[ //表头
        	  {field: 'sysRoleId', title: '',type:"checkbox", width:120, fixed: 'left'}
        	,{field: 'sysRoleId', title: '角色id', width:120, fixed: 'left'}
            ,{field: 'name', title: '角色名称', width:180}
            ,{field: 'roleCode', title: "角色code", width:120}
            ,{field: 'seq', title: "序号", width:120}
            ,{field: 'description', title: "角色简介", width:120}
            ,{field: 'createTime', title: '创建时间', width:220,templet: function(data){
                return formatDate(data.createTime,"yyyy-MM-dd hh:mm:ss");
            }} 
            ,{field: 'updateTime', title: '修改时间', width:220,templet: function(data){
                return formatDate(data.updateTime,"yyyy-MM-dd hh:mm:ss");
            }} 
          ]]
        });
        function searchFun(){
        	tableObj.reload({where:$("#searchWhereForm").serializeObject()});
        }
        $('#btn-search').on('click', function () {
        	searchFun();
        });
        
        
        
        function addOrEditData(dataId){
        	dataId = isNullGetDef(dataId,'');
        	var title = "添加角色";
        	if(isNotNull(dataId)){
        		title = "编辑角色";
        	}
        	openWindow({"title":title,"url":"/role/addOrEdit?dataId="+dataId},function(){
        		searchFun();
        	});
        }
        function giveMenu(dataId){
        	dataId = isNullGetDef(dataId,'');
        	var title = "分配权限";
        	openWindow({"title":title,"url":"/menu/giveManagerMenu?roleId="+dataId},function(){
        		searchFun();
        	});
        }
        function delData(dataId){
        	authManagerHttp({url:"/role/delData",data:{"dataId":dataId}},{success:function(data){
        		 searchFun();
        	}})
        }
        
        $('#btn-edit').on('click', function () {
        	var checkStatus = table.checkStatus('dateTable'); //test即为基础参数id对应的值
        	if(checkStatus.data.length != 1){
        		layer.msg("请选择一条记录"); 
        		return;
        	}
        	addOrEditData(checkStatus.data[0].sysRoleId);
        });
        $('#btn-give').on('click', function () {
        	var checkStatus = table.checkStatus('dateTable'); //test即为基础参数id对应的值
        	if(checkStatus.data.length != 1){
        		layer.msg("请选择一条记录"); 
        		return;
        	}
        	giveMenu(checkStatus.data[0].sysRoleId);
        });
        $('#btn-del').on('click', function () {
        	var checkStatus = table.checkStatus('dateTable'); //test即为基础参数id对应的值
        	if(checkStatus.data.length != 1){
        		layer.msg("请选择一条记录"); 
        		return;
        	}
        	delData(checkStatus.data[0].sysRoleId);
        });
        $('#btn-add').on('click', function () {
        	addOrEditData();
        });
        
    });
</script>
</body>
</html>